<?php

	class SendSMS
	{



		private static $instance;

		/**
		 * @return SendSMS
		 */
		public static function getInstance()
		{
			if (!self::$instance) {
				$class_name = 'SendSMS_' . Config_SMS::PROVIDER;
				self::$instance = new $class_name;
			}
			return self::$instance;
		}

		public function realSend($phone, $text, $sender = null) { }

		public static function pullSend($phone, $text, $from_hour = null)
		{

			if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 8880) {
				return false;
			}

			//validate and fix phone numbers
			$phone = str_replace(array(' ', '-', '(', ')', '+'), '', $phone);
			if ($phone[0] == '7') {
				$phone[0] = '8';
			}
			if (strlen($phone) != 11) {
				return false;
			}

			$db     = Database::getInstance();
			$phone  = $db->escape($phone);
			$text   = $db->escape($text);
			$sender = Config_SMS::SENDER;

			$db->query("INSERT INTO `sms_pull` SET
				`phone` = '{$phone}',
				`sender` = '{$sender}',
				`text` = '{$text}'
			");

			return true;
		}


	}
